name: CI

on:
  push:
    branches:  
    - master
    - 'releases/*'

jobs:
  build:
    runs-on: ubuntu-latest
    
    strategy:
      matrix:
        node-version: [ 16, 18 ]
    
    steps:
    - uses: actions/checkout@v3
    
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}

    - name: Cache node modules
      uses: actions/cache@v3
      env:
        cache-name: cache-node-modules
      with:
        path: ~/.npm    # npm cache files are stored in `~/.npm` on Linux
        key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
        restore-keys: |
          ${{ runner.os }}-build-${{ env.cache-name }}-
          ${{ runner.os }}-build-
          ${{ runner.os }}-

    - name: Install packages global
      run: |
        echo Installing angular cli
        npm install -g @angular/cli > /dev/null

    - name: Build accordion-sample app
      run: |
        echo Installing local packages and Building Sample app
        npm ci
        npm run build:sample --if-present

    - name: Make a drop
      uses: actions/upload-artifact@v3
      with:
        name: drop
        path: dist/accordion-sample

    - name: Run tests
      run: |
        echo Running tests
        npm run test:ci